// let promise1 = new Promise(function(resolve,reject){ 
//     setTimeout(function(){ 
//         resolve('ok') },1000) 
//     })
//     promise1.then(function success(val){ 
//         console.log(val) 
//     })
// 手写promise

class Promise { 
    constructor (process) {
        this.status = 'pending' 
        this.msg = '' 
        process(
            this.resolve.bind(this), 
            this.reject.bind(this)
        ) 
        return this
    }
    resolve (val) { 
        this.status = 'fulfilled' 
        this.msg = val 
    }
    reject (err) { 
        this.status = 'rejected' 
        this.msg = err 
    }
    then (fufilled, reject) { 
        if(this.status === 'fulfilled') { 
            fufilled(this.msg) 
        }
        if(this.status === 'rejected') { 
            reject(this.msg) 
        }
    }
}

class myPromise{
    constructor(process){
        this.status = 'pending'
        this.value = ''
    }
    process(){
        this.resolve.bind(this)
        this.reject.bind(this)
    }
    resolve(val){
        this.status === 'fulfilled'
        this.value = val
    }
    reject(err){
        this.status === 'rejected'
        this.value = err
    }
    then(fulfilled,rejected){
        if(this.status === 'fulfilled'){
            fulfilled(this.value)
        }
        if(this.status === 'rejected'){
            rejected(this.value)
        }
    }
}